<template>
    <view classs="adop">
        <uni-nav-bar fixed left-icon="left" title="审批通过" @clickLeft="backHandle" class="unibarS">
            <block slot="right">
                <text class="sub-btn" @click="subHandle()">提交</text>
            </block>
        </uni-nav-bar>
        <view class="adop-content">
            <u--form labelPosition="top" :model="formData" ref="uForm" labelWidth="80">
                <u-form-item class="item-box" label="备注信息：" labelPosition="top" ref="item1">
                    <u--textarea v-model="formData.approveDesc" border="false" placeholder="请输入备注信息" count
                        style="margin-top: 20rpx; background: #CCCCCC19;"></u--textarea>
                </u-form-item>
            </u--form>
        </view>
    </view>
</template>

<script>
export default {
    data() {
        return {
            formData: {
                approveResult: true,
                approveDesc: ''
            },
            subData: {},
            orderNumber: null,
            processName: null,
        }
    },
    onLoad(options) {
        if(options.orderNumber) {
            this.orderNumber = options.orderNumber
            this.getDetails()
        }
        const eventChannel = this.getOpenerEventChannel();
        let that = this
        // 监听acceptDataFromOpenerPage事件，获取上一页面通过eventChannel传送到当前页面的数据
        eventChannel.on('emitDataHandle', function(data) {
            // console.log(data)
            that.processName = data.data
        })
    },
    methods: {
        getDetails() {
            this.$http.get('/app/audit/querTodoTaskList', { orderNumber: this.orderNumber }).then(res => {
				if (res.code == 200) {
                    this.subData = res.data.records[res.data.records.length - 1].process
                    this.subData['businessCode'] = this.orderNumber
				}
			})
        },
        subHandle() {
            let obj = Object.assign({}, this.subData)
            obj['processName'] = this.processName
            obj['flyflow'] = {
                processInstanceId: this.subData.processInstanceId,
                taskId: this.subData.taskId,
                approveResult: this.formData.approveResult,
                approveDesc: this.formData.approveDesc
            }
            this.$http.post('/app/audit', obj).then(res => {
				if (res.data.code == 200) {
                    uni.showToast({ title: '操作成功', duration: 1000 });
                    setTimeout(() => {
                        uni.navigateBack()
                    }, 1000)
				}
			})
        },
        backHandle() {
            uni.navigateBack()
        }
    }
}
</script>

<style lang="scss" scoped>
.adop-content {
    margin-top: 32rpx;
}
.item-box {
    border-radius: 16rpx;
    background: rgba(255, 255, 255, 1);
    padding: 0 32rpx;
}
</style>